/***************
**
*
*公共JS
*
*/

$(function(){

	$(".modal-header .close").text('');//删除关闭	
	src_resize();//改变页面内容大小尺寸
	
	    //点击顶部 tab 关闭按钮
    $('.menutab').on('click','.menutab_title_close',function(){

        var menutab_length = $(".menutab_title").length;
        var menutab_index = $(".menutab_title").index($(this).parent())+1;
        if(menutab_length<=1){
            window.location.href = "index-index";
            return false;
        }

        $(this).parent().remove();
        var idkeynum = $(this).parent().attr('idkeynum');
        $('.cj'+idkeynum).remove();

        var mbtab = 0;//目标tab
        if(menutab_length>menutab_index){

        }else{
            mbtab = menutab_index-2;
        }

        $('.menutab_title').removeClass('active');
        $('.menutab_title').eq(mbtab).addClass('active');
        $('.cjall').hide();
        $('.cjall').eq(mbtab).show();
        return false;
    });

    //点击顶部 tab 某一项
    $('.menutab').on('click','.menutab_title',function(){
        $('.menutab_title').removeClass('active');
        $(this).addClass('active');
        var idkeynum = $(this).attr('idkeynum');
        $('.cjall').hide();
        $('.cj'+idkeynum).show();

        //导航菜单 增加选中效果
        $('.level1').removeClass('nav_click');
        $('.level2').removeClass('nav_click');
        $('#menulist'+idkeynum).addClass('nav_click');
    });
	
	//切换子菜单	一级导航
	$('.level1').on('click',function(){
		//导航菜单 增加选中效果
		$('.level1').removeClass('nav_click');
		$(this).addClass('nav_click');
		$('.level2').removeClass('nav_click');

		var url = $(this).attr('link');   //路径

		layer_load();//加载层
		var idkeynum = $(this).attr('idkeynum');

		if ($(".menutab_title"+idkeynum).length > 0 ) { 
			//已经存在当前菜单对应的tab 
			layer.closeAll('loading'); //关闭加载层
			$('.menutab_title').removeClass('active');
			$(".menutab_title"+idkeynum).addClass('active');
			
			$('.menutab_title').removeClass('top_menue_active');
			$(".menutab_title"+idkeynum).addClass('top_menue_active');
			
			$('.cjall').hide();
			$('.cj'+idkeynum).show();
		}else{
			//不存在当前菜单对应的tab
			$('.menutab_title').removeClass('active');
			var menutab_item = '<a class="btn menutab_title menutab_title'+idkeynum+' active" type="button" idkeynum="'+idkeynum+'">'+$(this).text()+' <i class="icon icon-times menutab_title_close"></i></a>';
			$('.menutab').append(menutab_item);
			
			$('.menutab_title').removeClass('top_menue_active');
			$(".menutab_title"+idkeynum).addClass('top_menue_active');

			if(url){
			   	$.ajax({
					type:'post',
					url:url,
					dataType:'html',
					success:function(data){
						layer.closeAll('loading'); //关闭加载层
						data = '<div class="cjall cj'+idkeynum+'" idkeynum="'+idkeynum+'">'+data+'</div>';
						$('.cj').append(data);

						$('#module_list').remove();
						$('.cjall').hide();
						$('.cj'+idkeynum).show();
					}				  
				}); 
			}
		}
	});

 	//切换子菜单	二级导航
  	$('.level2').on('click',function(){
  		layer_load();//加载层
  		//导航菜单 增加选中效果
  		$('.level2').removeClass('nav_click');
	  	$(this).addClass('nav_click');
			$('.level1').removeClass('nav_click');

	   	var url = $(this).attr('link');   //路径
		var idkeynum = $(this).attr('idkeynum');

		if ($(".menutab_title"+idkeynum).length > 0 ) { 
			//已经存在当前菜单对应的tab 
			layer.closeAll('loading'); //关闭加载层
			$('.menutab_title').removeClass('active');
			$(".menutab_title"+idkeynum).addClass('active');
			
			$('.menutab_title').removeClass('top_menue_active');
			$(".menutab_title"+idkeynum).addClass('top_menue_active');
			list_table();
			
			$('.cjall').hide();
			$('.cj'+idkeynum).show();
		}else{
			//不存在当前菜单对应的tab
			$('.menutab_title').removeClass('active');
			var menutab_item = '<a class="btn menutab_title menutab_title'+idkeynum+' active" type="button" idkeynum="'+idkeynum+'">'+$(this).text()+' <i class="icon icon-times menutab_title_close"></i></a>';
			$('.menutab').append(menutab_item);
			
			$('.menutab_title').removeClass('top_menue_active');
			$(".menutab_title"+idkeynum).addClass('top_menue_active');

			if(url){
			   	$.ajax({
					type:'post',
					url:url,
					dataType:'html',
					success:function(data){
						layer.closeAll('loading'); //关闭加载层
						data = '<div class="cjall cj'+idkeynum+'" idkeynum="'+idkeynum+'">'+data+'</div>';
						$('.cj').append(data);

						$('#module_list').remove();
						$('.cjall').hide();
						$('.cj'+idkeynum).show();
					}				  
				}); 
			}
		}
   	});
	   		
	//当点击 带有二级导航 的节点时，去除之前 选中节点 的 选中状态
	$('#menulist2,#menulist3').click(function(){
	  	$('.main_left_menu1').find('.nav_click').removeClass('nav_click');
	});

	//导航菜单 增加选中效果   
	var menu_list = '#'+$('#menu_list').val();
	$(menu_list).addClass('nav_click');
    
	
	//缩放左侧导航菜单
    $('.left_menu_onoff').click(function(){
    	var onoff = $(this).attr('onoff');
    	if(onoff && 'k' == onoff){
			//emarket
			//$(".infocollect").animate({margin:'0 20px 0 75px'},"slow");			
			
            $(".icon-chevron-right").hide(500);
    		$(".left_menu").animate({width:"55px"},"slow");
	    	$('.left_menu span').fadeOut();

	    	$('.weblogo').removeClass('weblogo_bg').addClass('weblogo_bg1').html('');
	    	$(this).attr('onoff','g');
	    	twoul_onoff();
	    	$('#menulist2').next().attr('btn_dis','y');
	    	var scrwidth=$(document.body).width()-56;//72;
	    	$(".main_right_content1").animate({width:scrwidth+'px'},"slow");
	    	$('#MyTable_tableLayout').animate({marginLeft:60+'px'},"slow");						
    	}else{
			//$(".infocollect").animate({margin:'0 20px 0 170px'},"slow");
			
    		$(".icon-chevron-right").show(300);
    		var twoul = $('#menulist1').next();
			if('on' == twoul.attr('dis')){
				twoul.css('display','block');
			}

	    	var twoul = $('#menulist2').next();
			if('on' == twoul.attr('dis')){
				twoul.css('display','block');
			}

			var twoul = $('#menulist3').next();
			if('on' == twoul.attr('dis')){
				twoul.css('display','block');
			}

    		$(this).attr('onoff','k');
    		//$(".left_menu").animate({width:"148px"},"slow");
    		$(".left_menu").animate({width:"180px"},"slow");

			$('.left_menu span').fadeIn(1000);
			$('.weblogo').removeClass('weblogo_bg1').addClass('weblogo_bg').html('现代终端建设');

			var scrwidth=$(document.body).width()-180;//148;

            $(".main_right_content1").animate({width:scrwidth+'px'},"slow");
            $('#MyTable_tableLayout').animate({marginLeft:0+'px'},"slow");
    	}
	});
	
	//当左侧菜单收起时，显示对应的标题
	$('.menu ul li').mouseover(function(){
		if($(".left_menu").css('width')=='55px'){
			layer.tips($(this).find('span').html(), $(this).find('i'), {tips: [2, '#333333']});
		}
	});

});

	$(window).resize(function() {
		src_resize();//改变页面内容大小尺寸
	});

	//基础设置 中 选项卡 切换
	function tablink(link){
		//导航菜单 增加选中效果
		$('.tablink').removeClass('menu_click');
		$(this).addClass('menu_click');

	   if(link!='undefined'){
		 $.ajax({
			  type:'post',
			  url:link,
			  dataType:'html',
			  success:function(data){
				  $('.tablediv1').html(data);
			  }				  
		  }); 
	   }
	}

	//改变页面内容大小尺寸
	function src_resize(){
		var height = $(window).height()-90;
		$('.infocollect').css('height',height);
		//是否是关闭或者打开左侧导航
		var onoff = $('.left_menu_onoff').attr('onoff');
		/*if(onoff == 'g'){			
			$(".infocollect").css('margin','0 20px 0 75px');
		}*/
		
		$('.main_content').css('height',height);

 		var left_menu_width = $('.left_menu').css('width');

        var ss = $(".filter-box").height();
     
 		var menu_width = left_menu_width.replace('px','');
 		var scrwidth=$(document.body).width()-menu_width;

 		$('.main_right_content1').css('width',scrwidth+'px');

		var scrHeight = $(window).height()-60;
		var scrHeightRight = scrHeight - 3;
       
        var scrHeightRightcon = scrHeight - 83- ss;

        $('.main_left_menu1').css('height',scrHeight+'px');
        var tree_height = scrHeightRightcon - 2;//树形结构高度
		$('.content_left_tree').css('min-height',tree_height+'px');
		var content_left_tree_height = $('.content_left_tree').height();
		if($('.content_left_tree').height()>(tree_height-35)){
			$('.devcontent_right').css('min-height',content_left_tree_height+'px');
		}else{
			$('.devcontent_right').css('min-height',tree_height+'px');
		}

		$('.devcontent').css('min-height',scrHeightRightcon+'px');//基本页面的高度
		var Nheight = scrHeightRightcon-20;
        $('.devcontentl').css('height',Nheight+'px');//tab页面的高度（客户信息首页）
        var Nheights = scrHeightRightcon+20;
        $('.devcontents').css('height',Nheights+'px');//添加页面的高度（新增日计划）
        var N_tree_height = Nheights-2;
        $('.content_left_tree_s').css('min-height',N_tree_height+'px');
    	$('.devonline_content_right').css('min-height',scrHeightRight+'px');
    	$('.devonline_content_right1').css('height',scrHeightRight+'px');

        var offsethg = scrHeight-$('.teaButs').height()-569;   /*教师中心左侧菜单底部的按钮位置*/

    	$('.teaButs').css('margin-top',offsethg+'px');  /*教师中心左侧菜单底部的按钮位置*/

	}
	
	function twoul_onoff(){
		var twoul = $('#menulist1').next();
		if('block' == twoul.css('display')){
			twoul.attr('dis','on');
			twoul.css('display','none');
		}else{
			twoul.attr('dis','off');
		}
		var twoul = $('#menulist2').next();
		if('block' == twoul.css('display')){
			twoul.attr('dis','on');
			twoul.css('display','none');
		}else{
			twoul.attr('dis','off');
		}

		var twoul = $('#menulist3').next();
		if('block' == twoul.css('display')){
			twoul.attr('dis','on');
			twoul.css('display','none');
		}else{
			twoul.attr('dis','off');
		}	
	}

	//加载层
	function layer_load(){
		layer.load(2, {content:'加载中...',shade: [0.6, '#393D49'],success: function(layero){
			layero.find('.layui-layer-content').css('width', '300px').css('color', '#fff').css('font-size', '26px').css('padding-left', '40px');
		}});
	}